package com.test2015.util.telnet;

import java.io.IOException;
import java.io.InputStream;

public class Telnet {
	
	
	public static void main(String[] args) throws IOException, InterruptedException {
		String cmd = "telnet 172.16.21.129";
		Runtime run = Runtime.getRuntime();
		Process exec = run.exec(cmd);
		InputStream is = exec.getInputStream();
		InputStream es = exec.getErrorStream();
		byte[] bytes = new byte[512];
		int read = -1;
		while((read = is.read(bytes))!= -1){
			System.out.println(new String(bytes,0,read));
		}
		
		while((read = es.read(bytes))!= -1){
			System.err.println(new String(bytes,0,read));
		}
		
		int waitFor = exec.waitFor();
		System.out.println(waitFor);
	}
}
